const load = (function () {

    let loadHander = () => {

    }


    let loding = () => {
        //ajax  http

        $(".header").load("./header.html", function () {

            loadHander();
        })
        $(".footer").load("./footer.html", function () {

        })

    }

    return {
        loding
    }
})();


$(function () {
    load.loding();
})



const list = (function () {

    axios.defaults.baseURL = "";

    const loadData = async () => {
        let data = await axios({
            url: "/data/list.json"
        })

        let res = data.data;

        console.log(res);
        let strHtml = ``;
        res.forEach(el => {
            strHtml += `
            <li>
                <a href="./details.html?c_id=${el.id}">
                <img src="${el.img}" alt="">
                <p class="pp1">${el.pname1} </p>
                <p class="pp2">${el.pname2} </p>
                <span class="s1">￥${el.price1}</span>
                <span class="s2">￥${el.price2}</span>
                </a>
            </li>`
        });
        $(".up").html(strHtml);
        ss();
    }

    function ss() {
        $(".up li").hover(function () {
            $(this).attr("class", "current").siblings().attr("class", "");
        }, function () {
            $(this).attr("class", "")
        })
    }

    return {
        loadData
    }

})()

function djs() {
    $(document).ready(function () {
        var oDate = new Date();
        var nowTime = oDate.getTime(); //现在的毫秒数
        oDate.setDate(oDate.getDate() + 5000); // 设定截止时间为第二天
        var targetDate = new Date(oDate.toLocaleDateString());
        getDate(targetDate);
    });
    function getDate(enddate) {
        var end = enddate;
        var cur = Date.now();
        var num = end - cur;
        var ms = num % 1000; //毫秒
        var ss = parseInt(num / 1000) % 60; //秒
        var mm = parseInt(num / 1000 / 60) % 60; //分
        var hh = parseInt(num / 1000 / 60 / 60) % 24; //小时
        var dd = parseInt(num / 1000 / 60 / 60 / 24); //天
        var spanH = $('.hours');
        var spanM = $('.minute');
        var spanS = $('.seconds');
        spanH.html(tow(hh));
        spanM.html(tow(mm));
        spanS.html(tow(ss));
    }

    function tow(n) {
        return n >= 0 && n < 10 ? '0' + n : '' + n;
    }
}

$(function () {
    list.loadData()
    setInterval(function () {
        djs();
    }, 500);
})






